home *** CD-ROM | disk | FTP | other *** search
- Hi,
-
- Try this:
-
- _zoom=256
- lens=256
- distance=_zoom-z
-
- X_Screen = (lens*(x/distance))+cx
- Y_Screen = cy-(lens*(y/distance))
-
- Where cx and cy are the coordinates of the centre of the screen.
- This method seems to cause some problems when objects are "behind" the
- camera, so be careful not to draw any point with distance<=0 (and 0 will mess
- up the division anyway).
-
- This gives you a 3D system with Cartesian x and y axes plus a z-axis sticking
- out towards you. Crappy ASCII diagram follows:
-
- Y
- |
- |
- |
- 0----------> X
- /
- /
- Z
-
-
- While I'm at it, here's some rotation formulae:
-
- To rotate a point about the world Y-axis:
-
- sang=sin(angle) : cang=cos(angle)
- tempx = (x * cang) + (z * sang)
- tempz = (z * cang) - (x * sang)
- y=tempy
- z=tempz
-
- (obviously some of these are floats, so stick the necessary # signs in in
- Amos)
-
- To rotate a point about the camera Y-axis (ie when you turn, rotate the
- object
- around the camera in the opposite direction):
-
- dz = z - _zoom
- tempx = (x * cang) + (dz * sang)
- tempz = ((dz * cang) - (x * sang)) + _zoom
- x=tempx
- y=tempy
-
- Rotations about the other axes can be derived from these. If you're still
- stuck,
- let me know and I'll see if I can help you further.
-
- Cheers,
-
- Matt Craven
- Hedgehog Software
- mcraven629@aol.com
-
-
-